package cn.fl.mfr.web.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.mfr.web.service.IMfrRlPsnService;
import cn.fl.mfr.web.transform.MfrRlPsnVOTransform;
import cn.fl.mfr.web.vo.MfrRlPsnVO;
import com.alibaba.fastjson.JSON;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.riskctrl.facade.brjf.api.IBrjfTelCheckApiService;
import fl.riskctrl.facade.py.api.IPyExecutiveApiService;
import fl.riskctrl.facade.py.api.IPyTelCheckApiService;
import fl.riskctrl.facade.td.api.ITdTelCheckApiService;
import fl.spl.facade.framework.annotation.FieldApply;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.mfr.api.IMfrInfoApiService;
import fl.spl.facade.mfr.api.IMfrInfoModDtlApiService;
import fl.spl.facade.mfr.api.IMfrRlPsnApiService;
import fl.spl.facade.mfr.condition.MfrInfoModDtlQC;
import fl.spl.facade.mfr.dto.MfrInfoDTO;
import fl.spl.facade.mfr.dto.MfrInfoModDtlDTO;
import fl.spl.facade.mfr.dto.MfrRlPsnDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @Description: 厂商关联人员信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class MfrRlPsnServiceImpl implements IMfrRlPsnService {

	@Autowired
	private IMfrInfoApiService mfrInfoApiService;
	
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	/**
	 * 百融三要素核查
	 * */
	@Autowired
	private IBrjfTelCheckApiService brjfTelCheckApiService ;
	/**
	 * 鹏元三要素核查
	 * */
	@Autowired
	private IPyTelCheckApiService pyTelCheckApiService ;
	/**
	 * 同盾三要素核查
	 * */
	@Autowired
	private ITdTelCheckApiService tdTelCheckApiService ;
	/**
	 * 鹏元企业信息核查
	 * */
	@Autowired
	private IPyExecutiveApiService pyExecutiveApiService ;

	@Autowired
	private IMfrRlPsnApiService mfrRlPsnApiService ;

	@Autowired
	private IMfrInfoModDtlApiService mfrInfoModDtlApiService ;

	@Override
	public MfrRlPsnVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		MfrRlPsnDTO dto = null;//this.自定义ApiService.selectMfrRlPsnDTOById(id);
		return MfrRlPsnVOTransform.toVO(dto);
	}

	@Override
	public Long add(MfrRlPsnVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"新增对象不存在!");
		};
		//return this.mfrRlPsnApiService.add(MfrRlPsnVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		//return this.mfrRlPsnApiService.removeMfrRlPsnDTOById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.newWebLogger("删除主键参数集合不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		}
		return this.mfrRlPsnApiService.removeMfrRlPsnDTOByIds(ids,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
    }

	@Override
	public boolean modify(MfrRlPsnVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("修改对象不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"修改对象不能为空!");
		}
		return this.mfrRlPsnApiService.modifyMfrRlPsnDTO(MfrRlPsnVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		page = this.mfrInfoApiService.searchMfrRlPsnListPage(page, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		@SuppressWarnings("unchecked")
		List<MfrRlPsnDTO> resultList = (List<MfrRlPsnDTO>) page.getResultList();
		page.setResultList(MfrRlPsnVOTransform.toVOList(resultList));
		return page;
				
	}
	
	@Override
	public List<KeyValueVO> searchCertTypCdList() throws BaseException{
		return this.getKvList(DictionaryConstant.CODE_GRP_CERT_TYP_CD);
	}
	
	@Override
	public List<KeyValueVO> searchRlTypCdList() throws BaseException{
		return this.getKvList(DictionaryConstant.CODE_RL_TYP_CD);
	}
	
	/**
	 * 根据字典中代码组值获取组员集合
	 * @param grpCd 代码组值
	 * @return 集合
	 */
	public List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.newWebLogger("获取字典项组失败，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			BaseLogUtils.newWebLogger("获取字典项组失败，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return kvList;
	}


	@Override
	public fl.riskctrl.facade.riskctrl.dto.DataResultDTO checkRlPsn(Map<String, String> map) throws BaseException {
		// TODO Auto-generated method stub
		fl.riskctrl.facade.riskctrl.dto.DataResultDTO resultDTO = new fl.riskctrl.facade.riskctrl.dto.DataResultDTO(BaseConstant.IS_YESNO_YES,"成功");
		if(CollectionUtils.isMapEmpty(map)){
			resultDTO.setInfo("数据为空");
			resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
			return resultDTO ;
		}
		Long dataId ;
		if(StringUtils.isNotEmpty(map.get("rlId"))){
			dataId = Long.valueOf(map.get("rlId"));
		}else if(StringUtils.isNotEmpty(map.get("applyPsnId"))){
			dataId = Long.valueOf(map.get("applyPsnId"));
		}else{
			resultDTO.setInfo("数据ID为空");
			resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
			return resultDTO ;
		}
		this.modifyMfrRlPsnCheckStatus(map,resultDTO,dataId) ;
		return resultDTO;
	}

	/**
	 * 修改联系人三方校验
	 * @param checkMap
	 * @param resultDTO
	 * @param dataId
	 * @return
	 */
	private fl.riskctrl.facade.riskctrl.dto.DataResultDTO modifyMfrRlPsnCheckStatus(Map<String, String> checkMap ,fl.riskctrl.facade.riskctrl.dto.DataResultDTO resultDTO,Long dataId){
		String checkTypCd = checkMap.get("type");
		String code ;
		MfrRlPsnDTO mfrRlPsnDTO = null ;
		String checkRlPsnInfoField = null ;
		if(StringUtils.isEmpty(checkTypCd)){
			resultDTO.setInfo("联系人类型为空！");
			resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
			return resultDTO ;
		}else{
			mfrRlPsnDTO = new MfrRlPsnDTO();
			switch (checkTypCd){
				case "verify":
					MfrInfoDTO mfrInfoDTO = this.mfrInfoApiService.selectPrdMfrInfoById(Long.valueOf(checkMap.get("busId")),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
					if("5".equals(checkMap.get("rlTypCd"))){
						resultDTO = this.pyExecutiveApiService.getPersonShareholderInfoCheck(dataId, checkMap.get("certNo"), checkMap.get("rlNm"), mfrInfoDTO.getMfrName(), null);
					}else{
						resultDTO = this.pyExecutiveApiService.getPersonArtificialInfoCheck(dataId, checkMap.get("certNo"), checkMap.get("rlNm"), mfrInfoDTO.getMfrName(), null);
					}
					if(resultDTO != null && resultDTO.getSuccess() == 1){
						code = (String)resultDTO.getData();
						if("一致".equals(code)){
							mfrRlPsnDTO.setBusInfoVerify("1");
						}else{
							mfrRlPsnDTO.setBusInfoVerify("-1");
						}
					}else{
						mfrRlPsnDTO.setBusInfoVerify("0");
					}
					checkRlPsnInfoField = "busInfoVerify";
					break;
				case "TD":
					resultDTO = this.tdTelCheckApiService.getTDTelCheck(dataId, checkMap.get("certNo"), checkMap.get("rlNm"), checkMap.get("tel"));
					if(resultDTO != null && resultDTO.getSuccess() == 1){
						code = (String)resultDTO.getData();
						if("一致".equals(code)){
							mfrRlPsnDTO.setTdPerVerify("1");
						}else{
							mfrRlPsnDTO.setTdPerVerify("-1");
						}
					}else{
						mfrRlPsnDTO.setTdPerVerify("0");
					}
					checkRlPsnInfoField = "tdPerVerify";
					break;
				case "PY":
					resultDTO = this.pyTelCheckApiService.getPYTelCheck(dataId, checkMap.get("certNo"), checkMap.get("rlNm"), checkMap.get("tel"));
					if(resultDTO != null && resultDTO.getSuccess() == 1){
						code = (String)resultDTO.getData();
						if("一致".equals(code)){
							mfrRlPsnDTO.setPyPerVerify("1");
						}else{
							mfrRlPsnDTO.setPyPerVerify("-1");
						}
					}else{
						mfrRlPsnDTO.setPyPerVerify("0");
					}
					checkRlPsnInfoField = "pyPerVerify";
					break;
				case "BR":
					resultDTO = this.brjfTelCheckApiService.getBRJFTelCheck(dataId, checkMap.get("certNo"), checkMap.get("rlNm"), checkMap.get("tel"),null);
					if(resultDTO != null && resultDTO.getSuccess() == 1){
						code = (String)resultDTO.getData();
						if("均一致".equals(code)){
							mfrRlPsnDTO.setByPerVerify("1");
						}else{
							mfrRlPsnDTO.setByPerVerify("-1");
						}
					}else{
						mfrRlPsnDTO.setByPerVerify("0");
					}
					checkRlPsnInfoField = "byPerVerify";
					break;
				default:
					break;
			}
		}

/*			Field[] field1 = mfrRlPsnDTO.getClass().getSuperclass().getDeclaredFields();
			Field[] field2  = mfrRlPsnDTO.getClass().getSuperclass().getFields();
			if(field1.length > 0){
				Annotation[] annotations = null ;
				for(Field field : field1){
					BaseLogUtils.info(logger, "checkRlPsn", "查询变更联系人信息,field1 ,field.getName："+field.getName());
					annotations = field.getDeclaredAnnotations();
					if(null != annotations && annotations.length > 0){
						for(Annotation annotation : annotations){
							BaseLogUtils.info(logger, "checkRlPsn", "查询变更联系人信息,field2 ,annotation："+annotation.annotationType());
						}
					}
				}
			}
			if(field2.length > 0){
				Annotation[] annotations = null ;
				for(Field field : field2){
					BaseLogUtils.info(logger, "checkRlPsn", "查询变更联系人信息,field2 ,field.getName："+field.getName());
					annotations = field.getAnnotations();
					if(null != annotations && annotations.length > 0){
						for(Annotation annotation : annotations){
							BaseLogUtils.info(logger, "checkRlPsn", "查询变更联系人信息,field2 ,annotation："+annotation.annotationType());
						}
					}
				}
			}*/

		String rlId = checkMap.get("rlId");
		String applyPsnId = checkMap.get("applyPsnId");
		String modId = checkMap.get("modId");
		boolean flag = this.modifyInfo(rlId,applyPsnId,mfrRlPsnDTO,checkRlPsnInfoField,modId);
		if(!flag){
			resultDTO.setInfo("三方校验厂商联系人失败！");
			resultDTO.setSuccess(BaseConstant.IS_YESNO_NO);
		}
		return resultDTO ;
	}

	/**
	 * 修改联系人校验状态
	 * @param rlId
	 * @param applyPsnId
	 * @param mfrRlPsnDTO
	 * @param checkRlPsnInfoField
	 * @return
	 */
	private boolean modifyInfo(String rlId,String applyPsnId,MfrRlPsnDTO mfrRlPsnDTO,String checkRlPsnInfoField,String modId){
		boolean b = false;
		if(StringUtils.isEmpty(applyPsnId) || StringUtils.isEmpty(modId)){
			mfrRlPsnDTO.setId(Long.valueOf(rlId));
			mfrRlPsnDTO.setMdfTm(new Date());
			mfrRlPsnDTO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			BaseLogUtils.newWebLogger("修改联系人三元素校验信息").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setKeys("mfrRlPsnDTO", JSON.toJSONString(mfrRlPsnDTO))
					.info();
			b = this.mfrRlPsnApiService.modifyMfrRlPsnDTO(mfrRlPsnDTO,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
		}else{
			//TODO 变更的联系人需要修改 ？？**************************
			MfrInfoModDtlQC mfrInfoModDtlQC = new MfrInfoModDtlQC() ;
			mfrInfoModDtlQC.setModBusId(Long.valueOf(applyPsnId));
			mfrInfoModDtlQC.setModId(Long.valueOf(modId));
			mfrInfoModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
			mfrInfoModDtlQC.setIsValid(BaseConstant.IS_YESNO_NO);
			List<MfrInfoModDtlDTO> mfrInfoModDtlDTOList = this.mfrInfoModDtlApiService.searchMfrInfoModDtlDTOList(mfrInfoModDtlQC);
			if(CollectionUtils.isEmpty(mfrInfoModDtlDTOList)){
				mfrRlPsnDTO.setId(Long.valueOf(applyPsnId));
				mfrRlPsnDTO.setMdfTm(new Date());
				mfrRlPsnDTO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
				BaseLogUtils.newWebLogger("修改联系人三元素校验信息").setLogOperType(LogOperEnum.REQ)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
						.setWarning(false)
						.setKeys("mfrRlPsnDTO", JSON.toJSONString(mfrRlPsnDTO))
						.info();
				b = this.mfrRlPsnApiService.modifyMfrRlPsnDTO(mfrRlPsnDTO,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
			}else{
				int isOrAdd = 0 ; //0:否,即修改，1：是，即新增
				for(MfrInfoModDtlDTO dtlDTO : mfrInfoModDtlDTOList){
					if(dtlDTO.getModAttrFiled().equalsIgnoreCase("id")){
						isOrAdd = 1 ;
						break;
					}
				}
				MfrInfoModDtlDTO mfrInfoModDtlDTO = null ;
				if(isOrAdd == 0){
					boolean isExist = false ;
					for(MfrInfoModDtlDTO dtlDTO : mfrInfoModDtlDTOList){
						if(dtlDTO.getModAttrFiled().equalsIgnoreCase(checkRlPsnInfoField)){
							isExist = true ;
							mfrInfoModDtlDTO = dtlDTO ;
						}
					}
					if(isExist){
						mfrInfoModDtlDTO.setMdfTm(new Date());
						mfrInfoModDtlDTO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
						try {
							Field field  = mfrRlPsnDTO.getClass().getSuperclass().getDeclaredField(checkRlPsnInfoField);
							field.setAccessible(true);

							PropertyDescriptor pd = new PropertyDescriptor(field.getName(),mfrRlPsnDTO.getClass().getSuperclass());

							Method method = pd.getReadMethod();

							mfrInfoModDtlDTO.setModConAft(String.valueOf(method.invoke(mfrRlPsnDTO)));
							//mfrInfoModDtlDTO.setModConAft(String.valueOf(field.get(checkRlPsnInfoField)));
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						} catch (IntrospectionException e) {
							e.printStackTrace();
						} catch (InvocationTargetException e) {
							e.printStackTrace();
						}
						DataResultDTO dataResultDTO = this.mfrInfoModDtlApiService.modifyMfrInfoModDtlDTO(mfrInfoModDtlDTO,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
						if(null != dataResultDTO && dataResultDTO.getSuccess() == BaseConstant.IS_YESNO_YES){
							b = true ;
						}
					}else{
						MfrRlPsnDTO rlPsnDTO = this.mfrRlPsnApiService.selectMfrRlPsnDTOById(Long.valueOf(applyPsnId),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
						if(null == rlPsnDTO){
							throw new BaseException(BaseExceptionConstant.COMMON_0002,BaseExceptionConstant.COMMON_0002_NAME);
						}
						MfrInfoModDtlDTO dto = CollectionUtils.isNotEmpty(mfrInfoModDtlDTOList) ? mfrInfoModDtlDTOList.get(0) :  null ;
						mfrInfoModDtlDTO = new MfrInfoModDtlDTO();
						mfrInfoModDtlDTO.setModBusId(Long.valueOf(applyPsnId));
						mfrInfoModDtlDTO.setModAttrFiled(checkRlPsnInfoField);
						try {
							Field field = mfrRlPsnDTO.getClass().getSuperclass().getDeclaredField(checkRlPsnInfoField);
							field.setAccessible(true);
							mfrInfoModDtlDTO.setModConAft(String.valueOf(field.get("checkRlPsnInfoField")));
							Annotation[] annotations = field.getDeclaredAnnotations();
							for(Annotation annotation : annotations){
								if(annotation instanceof FieldApply){
									FieldApply fieldApply = (FieldApply)annotation ;
									mfrInfoModDtlDTO.setModAttrCon(fieldApply.fieldDesc());
									mfrInfoModDtlDTO.setTabNm(fieldApply.tabNm());
								}
							}
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
							throw new BaseException(BaseExceptionConstant.COMMON_0002,BaseExceptionConstant.COMMON_0002_NAME);
						} catch (IllegalAccessException e) {
							e.printStackTrace();
							throw new BaseException(BaseExceptionConstant.COMMON_0002,BaseExceptionConstant.COMMON_0002_NAME);
						}
						/*if(StringUtils.isEmpty(modId)){
							throw new BaseException(BaseExceptionConstant.COMMON_0001,"变更业务主键不能为空！");
						}
						mfrInfoModDtlDTO.setModId(Long.valueOf(modId));
						mfrInfoModDtlDTO.setIsDel(BaseConstant.IS_YESNO_NO);
						mfrInfoModDtlDTO.setIsValid(BaseConstant.IS_YESNO_YES);
						mfrInfoModDtlDTO.setCrtTm(new Date());
						try {
							Field field = rlPsnDTO.getClass().getSuperclass().getDeclaredField(checkRlPsnInfoField) ;
							if(null != field){
								field.setAccessible(true);
								mfrInfoModDtlDTO.setModConBef(String.valueOf(field.get(checkRlPsnInfoField)));
							}
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
							throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
						} catch (IllegalAccessException e) {
							e.printStackTrace();
							throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
						}
						mfrInfoModDtlDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
						Long id  = this.mfrInfoModDtlApiService.addMfrInfoModDtlDTO(mfrInfoModDtlDTO,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
						if(StringUtils.isNotEmpty(id)){
							b = true ;
						}*/
					}
				}else if(isOrAdd == 1){
					//新增的变更联系人
					mfrRlPsnDTO.setId(Long.valueOf(applyPsnId));
					mfrRlPsnDTO.setMdfTm(new Date());
					mfrRlPsnDTO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
					BaseLogUtils.newWebLogger("修改联系人三元素校验信息").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setKeys("mfrRlPsnDTO", JSON.toJSONString(mfrRlPsnDTO))
							.info();
					b = this.mfrRlPsnApiService.modifyMfrRlPsnDTO(mfrRlPsnDTO,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.FL_WEB_CHL_CD,SplSystemConstant.SPL_SERVICE_CD);
				}
			}
		}
		if(b){
			BaseLogUtils.newWebLogger("修改厂商联系人信息成功").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.info();
		}else{
			BaseLogUtils.newWebLogger("修改厂商联系人信息失败").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
		}
		return  b;
	}

	@Override
	public Pager searchListPageByMask(Pager page, int isMask) throws BaseException {
		if(null == page){
			page = new Pager();
		}
		page = this.mfrInfoApiService.searchMfrRlPsnListPageByMask(page,isMask, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		@SuppressWarnings("unchecked")
		List<MfrRlPsnDTO> resultList = (List<MfrRlPsnDTO>) page.getResultList();
		page.setResultList(MfrRlPsnVOTransform.toVOList(resultList));
		return page;
				
	}
}
